package com.ruizhong.centercontroll.controller;


import com.ruizhong.centercontroll.entity.TFrame;
import com.ruizhong.centercontroll.service.TFrameService;
import com.ruizhong.centercontroll.util.Result;
import com.ruizhong.centercontroll.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iframe/api")
@CrossOrigin
public class TFrameController {

    @Autowired
    private TFrameService tFrameService;

    @GetMapping("/getAllIframe/{type}/{monItem}")
    public Result getAllIframe(@PathVariable(value = "type") Integer type, @PathVariable(value = "monItem") Integer monItem) {
        List<TFrame> allIframe = tFrameService.getAllIframe(type, monItem);
        return new Result(ResultCode.success, null, allIframe);
    }

    @PostMapping("/submitNewIframe")
    public Result submitNewIframe(@RequestBody TFrame tFrame) {
        tFrameService.submitNewIframe(tFrame);
        return new Result(ResultCode.success, null, null);
    }

    @PostMapping("/updateIframeInfo")
    public Result updateIframeInfo(@RequestBody TFrame tFrame) {
        tFrameService.updateIframeInfo(tFrame);
        return new Result(ResultCode.success, null, null);
    }

    @GetMapping("/getIframeDetailById/{id}")
    public Result getIframeDetailById(@PathVariable(value = "id") Integer id) {
        TFrame iframeDetail = tFrameService.getIframeDetailById(id);
        return new Result(ResultCode.success, null, iframeDetail);
    }

    @DeleteMapping("/deleteFrameById/{id}")
    public Result deleteFrameById(@PathVariable(value = "id") Integer id) {
        tFrameService.deleteFrameById(id);
        return new Result(ResultCode.success, null, null);
    }

    @GetMapping("/getAllIframe")
    public Result getAllIframe() {
        List<TFrame> iframeDetail = tFrameService.getAllIframe();
        return new Result(ResultCode.success, null, iframeDetail);
    }

    @GetMapping("/checkMonMenuIsAim/{menuId}/{aimMon}")
    public Result checkMonMenuIsAim(
            @PathVariable(value = "menuId") Integer menuId,
            @PathVariable(value = "aimMon") String aimMon
    )
    {
        String res = tFrameService.checkMonMenuIsAim(menuId,aimMon);
    return new Result(ResultCode.success,null,res);
    }

}
